//
//  WeiBoViewController.m
//  Games
//
//  Created by iOS Two on 14/12/31.
//  Copyright (c) 2014年 iOS Two. All rights reserved.
//

#import "WeiBoViewController.h"
#import "UIImage+GIF.h"
#import "NSData+GIF.h"

@interface WeiBoViewController ()

@end

@implementation WeiBoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creatController];
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
    label.text = @"新浪微博";
    label.font = [UIFont fontWithName:@"MFYaYuan_Noncommercial-Regular" size:20];
    label.textColor = [UIColor colorWithRed:0.98 green:0.59 blue:0.16 alpha:1];
    label.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = label;
    self.view.backgroundColor  = [UIColor whiteColor];
    UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStyleDone target:self action:@selector(buttonClick:)];
    self.navigationItem.rightBarButtonItem = button;
    // Do any additional setup after loading the view.
}
-(void)creatController {
    UIImageView *back = [[UIImageView alloc]initWithFrame:CGRectMake(0, 150, kwidth, 218)];
    if (kwidth == 414) {
        back.image = [UIImage imageNamed:@"weibo_02@3x"];
    } else if (kwidth == 320) {
        back.image = [UIImage imageNamed:@"weibo_02"];
    } else {
        back.image = [UIImage imageNamed:@"weibo_02"];
    }
    [self.view addSubview:back];
    
    UIImage *weiboImage = [UIImage imageNamed:@"ditu_02@3x"];
    UIImageView *weibo = [[UIImageView alloc]initWithFrame:CGRectMake(0, kHeight - weiboImage.size.height, kwidth, weiboImage.size.height)];
    weibo.image = weiboImage;
    [self.view addSubview:weibo];
    
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(28, 100, 93, 93)];
    image.image = [UIImage sd_animatedGIFWithData:_imageData];
    image.transform=CGAffineTransformMakeRotation(-0.3);
//    image.layer.cornerRadius = 3;
    image.layer.borderWidth = 1;
    image.layer.borderColor = [[UIColor colorWithRed:0.71 green:0.62 blue:0.2 alpha:1] CGColor];
    [self.view addSubview:image];
    
    _text = [[UITextView alloc]initWithFrame:CGRectMake(51, 215, 414-30-51, 145)];
    _text.font = [UIFont systemFontOfSize:15];
    _text.delegate = self;
    _text.textColor = [UIColor colorWithRed:0.41 green:0.41 blue:0.4 alpha:1];
    [_text becomeFirstResponder];
    [self.view addSubview:_text];
    if (kwidth == 320) {
        _text.frame = CGRectMake(32, 215, 320-30-20, 145);
    } else if (kwidth == 375) {
        _text.frame = CGRectMake(40, 215, 375-40-20, 145);
    }
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [_text resignFirstResponder];
}
-(void)textViewDidEndEditing:(UITextView *)textView {
    [_text resignFirstResponder];
}
-(void)buttonClick:(UIButton *)sender {
    if ([_text.text isEqualToString:@""]) {
        [self alertViewShow:@"请输入文字"];
    } else {
        id<ISSContent> publishContent ;
        if (_isPath) {
            publishContent = [ShareSDK content:_text.text
                                defaultContent:@"测试一下分享Gif图片"
                                         image:[ShareSDK imageWithPath:_image]
                                         title:@"ShareSDK"
                                           url:@"http://www.mob.com"
                                   description:@"这是一条测试信息"
                              //注意此分享Gif的类型只适用于微信
                                     mediaType:SSPublishContentMediaTypeImage];
        } else {
            publishContent = [ShareSDK content:_text.text
                                defaultContent:@"测试一下分享Gif图片"
                                         image:[ShareSDK imageWithUrl:_image]
                                         title:@"ShareSDK"
                                           url:@"http://www.mob.com"
                                   description:@"这是一条测试信息"
                              //注意此分享Gif的类型只适用于微信
                                     mediaType:SSPublishContentMediaTypeImage];
        }
        //自定义UI分享
        [ShareSDK shareContent:publishContent
                          type:ShareTypeSinaWeibo
                   authOptions:nil
                  shareOptions:nil
                 statusBarTips:YES
                        result:^(ShareType type, SSResponseState state, id<ISSPlatformShareInfo> statusInfo, id<ICMErrorInfo> error, BOOL end) {
                            if (state == SSPublishContentStateSuccess) {
                                NSLog(NSLocalizedString(@"TEXT_SHARE_SUC", @"发表成功"));
                                [self alertViewShow:@"发送成功"];
                            } else if (state == SSPublishContentStateFail) {
                                NSLog(NSLocalizedString(@"TEXT_SHARE_FAI", @"发布失败!error code == %d, error code == %@"), [error errorCode], [error errorDescription]);
                                NSLog(@"%ld  %@",(long)[error errorCode],[error errorDescription]);
                            }
                        }];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
